import { execute, select } from '../../utils/db';
import { SiteConfig } from '../../types/siteConfig';

export class SiteConfigDao  {

  // 更新配置
  static async update(config: SiteConfig) {
    const sql = `
      UPDATE site_config
      SET logo = ?, unit_name = ?, system_name = ?,
          ip_addr = ?, port = ?
      WHERE id = ?
    `;
    return await execute(sql, [
      config.logo,
      config.unit_name,
      config.system_name,
      config.ip_addr,
      config.port,
      config.id
    ]);
  }


  // 查询单个配置
  static async getById(id: number): Promise<SiteConfig> {
    const result = await select<SiteConfig[]>(
      'SELECT * FROM site_config WHERE id = ? LIMIT 1',
      [id]
    )
    return result.length > 0 ? result[0] : {} as SiteConfig;
  }
}